package cn.bonoon.kernel.util;

/**
 * 一些简单的加载和解密算法的实现
 * 
 * @author jackson
 * 
 */
public final class SimpleEncryptUtil {
	private static final byte[] FACTOR = { 0X0, 0X1, 0X2, 0X3, 0X4, 0X5, 0X6,
			0X7, 0X8, 0X9, 0XA, 0XB, 0XC, 0XD, 0XE, 0XF };
	static {
		for (int i = 0; i < FACTOR.length; i++) {
			int p = (int) (Math.random() * 100) % FACTOR.length;
			byte b = FACTOR[i];
			FACTOR[i] = FACTOR[p];
			FACTOR[p] = b;
		}
	}

	public static final String encrypt(String str) {
		byte[] bs = str.getBytes();
		for (int i = 0; i < bs.length; i++) {
			byte b = FACTOR[i % FACTOR.length];
			bs[i] = (byte) (bs[i] ^ b);
		}
		return new String(bs);
	}
}
